<template>
    <div>
      <h1>房号添加</h1>
      <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">房型</td>
                    <td>
                        <select v-model="query.typeName">
                          <option value="">请选择</option>
                          <option value="单人房">单人房</option>
                          <option value="双人房">双人房</option>
                          <option value="大床房">大床房</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td align="right">房号名称</td>
                    <td>
                        <input type="text" v-model="query.numberName"/>
                    </td>
                </tr>
                <tr>
                    <td align="right">房号编号</td>
                    <td>
                        <input type="text" v-model="query.numberNum"/>
                    </td>
                </tr>
                <tr>
                    <td align="right">房号备注</td>
                    <td>
                        <textarea v-model="query.desc"></textarea>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="添加" class="btn btn-primary" @click="ok"/>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref,reactive,onMounted } from 'vue';
import { useRoute,useRouter } from 'vue-router';
const router=useRouter();
const route=useRoute();

let query:any=reactive
({
  "typeName": "",
  "numberName": "",
  "numberNum": "",
  "desc": ""
})

const ok=()=>
{
    if(query.typeName=="")
    {
        alert("房型不能为空");
        return;
    }
    if(query.numberName=="")
    {
        alert("房号不能为空");
        return;
    }
    if(query.numberNum=="")
    {
        alert("编号不能为空");
        return;
    }
    if(query.desc=="")
    {
        alert("备注不能为空");
        return;
    }
    axios
    ({
        url:'/api/House/NumberAdd',
        method:'post',
        data:query
    })
    .then(res=>{
        if(res.data==-1)
        {
            alert("房号重复");
            return;
        }
        if(res.data>0)
        {
            alert("添加成功");
            router.push('/numberList');
            return;
        }
        else
        {
          alert("添加失败");
          return;
        }
    })
    .catch(err=>{

    })
}

</script>

<style scoped>

</style>